home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 3 / Example 3.1 / intpoint.h < prev   
Encoding:
C/C++ Source or Header  |  2006-06-12  |  1.3 KB  |  33 lines

  1. #ifndef _INTPOINT
  2. #define _INTPOINT
  3.  
  4. #include <d3dx9.h>
  5. #include <math.h>
  6. #include "debug.h"
  7.  
  8. class INTPOINT{
  9.     public:
  10.         INTPOINT(){x = y = 0;}
  11.         INTPOINT(int _x, int _y){Set(_x,_y);}
  12.  
  13.         void operator=(const POINT rhs){x = rhs.x;y = rhs.y;}
  14.         bool operator==(const INTPOINT rhs){return rhs.x == x && rhs.y == y;}
  15.         bool operator!=(const INTPOINT rhs){return rhs.x != x || rhs.y != y;}
  16.         void operator+=(const INTPOINT rhs){x += rhs.x; y += rhs.y;}
  17.         void operator/=(const int rhs){x /= rhs; y /= rhs;}
  18.         INTPOINT operator*(const INTPOINT rhs){return INTPOINT(x * rhs.x, y * rhs.y);}
  19.         INTPOINT operator/(const INTPOINT rhs){return INTPOINT(x / rhs.x, y / rhs.y);}
  20.         INTPOINT operator/(const int d){return INTPOINT(x / d, y / d);}
  21.         INTPOINT operator-(const INTPOINT &rhs){return INTPOINT(x - rhs.x, y - rhs.y);}
  22.         INTPOINT operator+(const INTPOINT &rhs){return INTPOINT(x + rhs.x, y + rhs.y);}
  23.         INTPOINT operator-(const int &rhs){return INTPOINT(x - rhs, y - rhs);}
  24.         INTPOINT operator+(const int &rhs){return INTPOINT(x + rhs, y + rhs);}
  25.  
  26.         float Distance(INTPOINT p){return sqrtf((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));}
  27.         bool inRect(RECT r){if(x < r.left || x > r.right || y < r.top || y > r.bottom)return false;else return true;}
  28.  
  29.         void Set(int _x, int _y){x = _x; y = _y;}
  30.         int x,y;
  31. };
  32.  
  33. #endif